// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ThreadObjectFactory.java

package org.quickserver.util.pool.thread;

import org.apache.commons.pool.BasePoolableObjectFactory;

// Referenced classes of package org.quickserver.util.pool.thread:
//            ClientThread, ClientPool

public class ThreadObjectFactory extends BasePoolableObjectFactory
{

    public ThreadObjectFactory()
    {
        id = -1;
        id = ++instanceCount;
    }

    public void setClientPool(ClientPool pool)
    {
        this.pool = pool;
    }

    public Object makeObject()
    {
        ClientThread ct = new ClientThread(pool, id);
        ct.start();
        return ct;
    }

    public void passivateObject(Object obj)
    {
        ((ClientThread)obj).clean();
    }

    public void activateObject(Object obj1)
    {
    }

    public void destroyObject(Object obj)
    {
        if(obj == null)
        {
            return;
        } else
        {
            Thread thread = (Thread)obj;
            thread.interrupt();
            thread = null;
            return;
        }
    }

    public boolean validateObject(Object obj)
    {
        if(obj == null)
        {
            return false;
        } else
        {
            Thread thread = (Thread)obj;
            return thread.isAlive();
        }
    }

    private ClientPool pool;
    private static int instanceCount = 0;
    private int id;

}
